<template>
    <div class="app-container">
        <div class="shop_container">
            <div class="flex3">
                <authorize />
            </div>
            <div class="flex2">
                <expire />
            </div>
        </div>
        <el-card class="box-card" style="margin-top: 40px;">
            <div>
                <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
                    <el-form-item label="" prop="productNum">
                        <el-input v-model="queryParams.searchValue" prefix-icon="el-icon-search" placeholder="请输入搜索内容"
                            clearable style="width: 240px" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item label="" prop="shopType">
                        <el-select v-model="queryParams.shopType" placeholder="平台" clearable style="width: 240px">
                            <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel"
                                :value="dict.dictValue" />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="" prop="state">
                        <el-select v-model="queryParams.state" placeholder="子账号" clearable style="width: 240px">
                            <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel"
                                :value="dict.dictValue" />
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="cyan" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>

                <el-table v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="50" align="center" />
                    <el-table-column label="店铺编号" align="center" prop="shopId" show-overflow-tooltip />
                    <el-table-column label="LOGO" align="center" prop="productNum" width="180">
                        <template slot-scope="scope">
                            <div>
                                <img :src="scope.row.shopLogo" alt="" srcset="" width="60" height="60">
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="店铺名称" align="center" prop="shopName" width="180"
                        :show-overflow-tooltip="true" />
                    <el-table-column label="店铺类型" align="center" prop="shopType" width="140" />
                    <el-table-column label="关联的子账号" align="center" prop="productType" width="140" />
                    <el-table-column label="授权过期时间" align="center" prop="createTime" width="160">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.createTime) }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="备注" align="center" prop="remark" width="140" />
                    <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220">
                        <template slot-scope="scope">
                            <el-button type="primary" plain @click="handleUpdate(scope.row)"
                                v-hasPermi="['']">编辑</el-button>
                            <el-button type="danger" plain @click="handleDelete(scope.row)"
                                v-hasPermi="['']">删除店铺</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getProductList" />

                <el-drawer :title="drawerTitle" :visible.sync="drawerStatus" direction="rtl"
                    :before-close="handleClose">
                    <el-form ref="form" :model="drawerForm" label-width="120px">
                        <el-form-item label="子账户">
                            <el-select v-model="drawerForm.region" style="width:80%" placeholder="请选择">
                                <el-option label="关联" value="1"></el-option>
                                <el-option label="不关联" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="备注">
                            <el-input v-model="drawerForm.remark" style="width:80%" placeholder="请输入"></el-input>
                        </el-form-item>
                        <div style="margin-top: 40px; text-align: center;">
                            <el-button type="primary">立即创建</el-button>
                            <el-button @click="handleClose">取消</el-button>
                        </div>
                    </el-form>
                </el-drawer>
            </div>
        </el-card>

    </div>
</template>

<script>
import authorize from './components/authorize.vue'
import expire from './components/expire.vue'
import { getShopList, deleteShop } from '@/api/product/productInfo'



export default {
    name: "shop111",
    components: { authorize, expire },
    data() {
        return {
            drawerTitle: '',
            drawerStatus: false,
            loading: false,
            total: 0,
            tableData: [],
            statusOptions: [],
            drawerForm: {},
            // 查询参数
            queryParams: {
                currentPage: 1,
                pageSize: 10,
                productNum: undefined,
                productName: undefined,
                productType: undefined,
                state: undefined,
                tradeFace: undefined
            },
        };
    },

    created() {
    },
    mounted() {
        this.getList()
    },
    watch: {
        queryParams(val) {
            if (val) {
                this.getList()
            }
        }
    },
    methods: {
        getList() {
            getShopList(this.queryParams).then(res => {
                this.tableData = res.value?.list || []
                this.total = res.value?.total || 0
            })
        },
        handleUpdate(query) {
            this.drawerTitle = `正在编辑店铺: ${query.agtNo} 的数据信息`
            this.drawerStatus = true
        },
        handleClose() {
            this.drawerStatus = false
            this.drawerForm = {}
        },
        handleDelete(scope) {
            this.$confirm('确定要删除当前数据吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                // this.$store.dispatch('LogOut').then(() => {
                //     location.href = '/index';
                // })
                deleteShop(scope.id).then(res => {
                console.log('res', res);
            })
            })
            

        },
        handleSelectionChange(selection) {

        },
        getProductList() {

        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.page = 1;
            this.getProductList();
        },

        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
    }
};
</script>

<style lang="scss" scope>
.shop_container {
    display: flex;

    .flex3 {
        flex: 3;
        margin-right: 20px;
    }

    .flex2 {
        flex: 2;
    }
}
</style>